package com.neuedu.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.neuedu.pojo.MailVo;
import com.neuedu.util.CommonResult;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
@RestController
@RequestMapping("/sendmail")
public class MailSendAdmin {

    @Resource
    ObjectMapper objectMapper;
    @Resource
    RabbitTemplate rabbitTemplate;

    @PostMapping("/sendmq")
    CommonResult sendmq(@RequestBody  MailVo mailVo){
        try {
            rabbitTemplate.convertAndSend("mailqueue",objectMapper.writeValueAsString(mailVo));
            return CommonResult.success("发送到mq成功");
        } catch (JsonProcessingException e) {
            e.printStackTrace();
            return CommonResult.failed("发送异常");
        }

    }
    
}
